import numpy as np
import concurrent.futures


def test_function(a, b):
    return a + b, a * b


if __name__ == '__main__':
    a_range = [i for i in range(5)]
    b_range = [4 for i in range(len(a_range))]

    futures_list = []
    with concurrent.futures.ProcessPoolExecutor() as executor:
        for i, j in zip(a_range, b_range):
            future = executor.submit(test_function, i, j)  # submit方法，不能保证函数返回值的顺序
            futures_list.append(future)

        done, not_done = concurrent.futures.wait(futures_list)  # wait方法返回两个集合：已完成的 Future 对象和未完成的 Future 对象

        # 取出数据
        data = []
        for future in done:
            data.append(future.result())  # 使用submit方法，future对象需要调用result方法

        print(data)

